package cn.wk.dao.impl;

import cn.wk.dao.ScoreDao;
import cn.wk.entity.Admins;
import cn.wk.entity.Score;
import cn.wk.util.JDBCUtil;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class ScoreDaoImpl implements ScoreDao {
    private JdbcTemplate template=new JdbcTemplate(JDBCUtil.getDataSource());
    @Override
    public List<Score> getAll(Object...obj) {
        String sql="select sid, stuname,couname,subject from score s,course c,stuinfo stu,teacher t " +
                " where s.stuid=stu.stuid and " +
                " s.couid=c.couid and c.tid=t.tid and t.tno=? " +
                "and c.couname=? limit ?,?";
        List<Score>list=template.query(sql,new BeanPropertyRowMapper<>(Score.class),obj);
        return list;
    }
    @Override
    public List<Score> getAlls(Object...obj) {
        String sql="select sid, stuname,couname,subject from score s,course c,stuinfo stu,teacher t " +
                " where s.stuid=stu.stuid and " +
                " s.couid=c.couid and c.tid=t.tid and t.tno=? " +
                "and c.couname=? ";
        List<Score>list=template.query(sql,new BeanPropertyRowMapper<>(Score.class),obj);
        return list;
    }


    @Override
    public int MdiffScore(int subject,int sid) {
        String sql="update score set subject=? where sid=?;";
        int b=template.update(sql,subject,sid);
        return b;
    }

    @Override
    public int CountSize(Object...obj) {
        String sql="select count(*) from  score s,course c " +
                " where s.couid=c.couid and c.couname=?";
        int b=template.queryForObject(sql,Integer.class,obj);
        return b;
    }
}
